/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
function selectLocation() {
	// Gather location id or coordinates
	var officer_id = document.getElementById( "officer-gather-information-id" ).value;
	
	var location_id = document.getElementById( "officer-gather-information-location" );
	if( location_id.value && location_id.value != -1 ) {
		location_id = location_id.value;
		YAHOO.util.Connect.asyncRequest( "GET", "get_location.php?location_id=" + location_id + "&officer_id=" + officer_id, selectLocationCallback, null );
	}
	else {
		var x = document.getElementById( "officer-gather-information-x" );
		var y = document.getElementById( "officer-gather-information-y" );
		if( x && x.value && y && y.value ) {
			x = x.value;
			y = y.value;
			YAHOO.util.Connect.asyncRequest( "GET", "get_location.php?x=" + x + "&y=" + y + "&officer_id=" + officer_id, selectLocationCallback, null );
		}
		else {
			alert( "Please fill in some coordinates or select a location first." );
		}
	}
}

var selectLocationSuccess = function( o ) { 
	var container = document.getElementById( "officer-gather-information" );
	container.innerHTML = o.responseText;
}

var selectLocationFailure = function( o ) { 
	alert( "There was a problem retrieving the location information.\n" +
			"\n" +
			"Status message: " + o.statusText );
}

var selectLocationCallback = {
	success: selectLocationSuccess,
	failure: selectLocationFailure
};

function getArmyInformation( army_id, officer_id ) {
	YAHOO.util.Connect.asyncRequest( "POST", "get_army_information.php", getArmyInformationCallback, "army_id=" + army_id + "&officer_id=" + officer_id );
}

var getArmyInformationSuccess = function( o ) { 
	var container = document.getElementById( "officer-gather-information" );
	container.innerHTML = o.responseText;
}

var getArmyInformationFailure = function( o ) { 
	alert( "There was a problem retrieving the army information.\n" +
			"\n" +
			"Status message: " + o.statusText );
}

var getArmyInformationCallback = {
	success: getArmyInformationSuccess,
	failure: getArmyInformationFailure
};

function backToSelectLocation( officer_id ) {
	YAHOO.util.Connect.asyncRequest( "GET", "select_location.php?officer_id=" + officer_id, backToSelectLocationCallback, null );
}

var backToSelectLocationSuccess = function( o ) { 
	var container = document.getElementById( "officer-gather-information" );
	container.innerHTML = o.responseText;
}

var backToSelectLocationFailure = function( o ) { 
	alert( "There was a problem retrieving the proper information, please refresh the page.\n" +
			"\n" +
			"Status message: " + o.statusText );
}

var backToSelectLocationCallback = {
	success: backToSelectLocationSuccess,
	failure: backToSelectLocationFailure
};
